<%@	page contentType="text/html; charset=utf-8"%>
<%@page import="com.appspot.yeswether.KoreanDateUtil"%>
<%@page import="com.appspot.yeswether.Weather"%>
<%@page import="com.appspot.yeswether.jdo.WeatherManager"%>
<%@page import="java.util.*" %>
<%	
	String code="CT001013";
	
	if(request.getParameter("code") !=null){
		code=request.getParameter("code");
	}

	String today=KoreanDateUtil.getDateString(0);
	String yesterday = KoreanDateUtil.getDateString(-1);
	
	WeatherManager manager = new WeatherManager();
	
	Weather yester=manager.getWeather(code, yesterday);
	Weather weather =manager.getWeather(code, today); 

	if(weather ==null ){
		weather =new Weather();
	}
	if(yester==null) {
		yester=new Weather();
	}
	
	String todayImg="/img/t0.jpg";
	String tomorrowImg="/img/tt0.jpg";
	try{
		double yesterTemp=Double.parseDouble(yester.getMorningTemp().trim())+Double.parseDouble(yester.getEveningTemp().trim());
		double todayTemp=Double.parseDouble(weather.getMorningTemp().trim())+Double.parseDouble(weather.getEveningTemp().trim());
		double tomorrowTemp=Double.parseDouble(weather.getTmorningTemp().trim())+Double.parseDouble(weather.getTeveningTemp().trim());		
		
		if(yesterTemp - todayTemp > 0){ // 오늘이 더 추우면 
			if(Math.abs(yesterTemp-todayTemp)>7){
				todayImg="/img/t4.jpg";
			}else if (Math.abs(yesterTemp-todayTemp)>2){
				todayImg="/img/t3.jpg";
			}else {
				todayImg="/img/t0.jpg";
			}
		}else if( yesterTemp - todayTemp < 0) { // 오늘이 더 따뜻하면 
			if(Math.abs(yesterTemp-todayTemp)>7){
				todayImg="/img/t2.jpg";
			}else if (Math.abs(yesterTemp-todayTemp)>2){
				todayImg="/img/t1.jpg";
			}else {
				todayImg="/img/t0.jpg";
			}		
		}
		
		if(todayTemp - tomorrowTemp > 0){ // 내일이 더 추우면 
			if(Math.abs(todayTemp - tomorrowTemp)>7){
				tomorrowImg="/img/tt4.jpg";
			}else if (Math.abs(todayTemp-tomorrowTemp)>2){
				tomorrowImg="/img/tt3.jpg";
			}else {
				tomorrowImg="/img/tt0.jpg";
			}			
		}else if( todayTemp - tomorrowTemp < 0) { // 내일이 더 따뜻하면 
			if(Math.abs(todayTemp - tomorrowTemp)>7){
				tomorrowImg="/img/tt2.jpg";
			}else if (Math.abs(todayTemp-tomorrowTemp)>2){
				tomorrowImg="/img/tt1.jpg";
			}else {
				tomorrowImg="/img/tt0.jpg";
			}		
		}		
	}catch(Exception e){
	}
	
%>
<!DOCTYPE html> 
<html> 
	<head> 
	<title>My Page</title> 
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	
	<%-- 
	<link rel="stylesheet" href="/jquery/jquery.mobile-1.0.min.css" /> 
	<script type="text/javascript" src="/jquery/jquery-1.6.4.min.js"></script>
	<script type="text/javascript" src="/jquery/jquery.mobile-1.0.min.js"></script>
	--%>
</head> 
<body bgcolor="FFFFFF">

	<table>
		<tr>
			<td>접속일 : <%=KoreanDateUtil.getToday() %></td>
			<td>접속 지역 : <%=weather.getRegionName() %></td>
		</tr>
	</table> 

	<table>
		<tr>
			<td>
				<img src="<%=todayImg %>">
			</td>
		</tr>
	</table>
	
	<table>
		<tr>
			<td>어제 오전</td>
			<td>오늘 오전</td>
			<td>내일 오전</td>
		</tr>
		<tr>
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=yester.getMorningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=yester.getMorningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=yester.getMorningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=yester.getMorningRainPercent() %>%
						</td>
					</tr>										
				</table>
			</td>
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=weather.getMorningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=weather.getMorningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=weather.getMorningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=weather.getMorningRainPercent() %>%
						</td>
					</tr>										
				</table>			
			</td>									
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=weather.getTmorningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=weather.getTmorningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=weather.getTmorningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=weather.getTmorningRainPercent() %>%
						</td>
					</tr>										
				</table>			
			</td>
		</tr>		
	</table>
				
	
	<hr>
	
	<table>
		<tr>
			<td>
				<img src="<%=tomorrowImg %>">
			</td>
		</tr>			
	</table>
									
	<table>
		<tr>
			<td>어제 오후</td>
			<td>오늘 오후</td>
			<td>내일 오후</td>
		</tr>
		<tr>
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=yester.getEveningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=yester.getEveningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=yester.getEveningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=yester.getEnveningRainPercent() %>%
						</td>
					</tr>										
				</table>
			</td>
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=weather.getEveningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=weather.getEveningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=weather.getEveningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=weather.getEnveningRainPercent() %>%
						</td>
					</tr>										
				</table>			
			</td>									
			<td>
				<table>
					<tr>
						<td>
							<img src="<%=weather.getTeveningImg() %>" width="70">
						</td>
					</tr>
					<tr>
						<td>
							<%=weather.getTeveningTxt() %>
						</td>
					</tr>
					<tr>
						<td>
							기온 	<%=weather.getTeveningTemp() %>℃
						</td>
					</tr>
					<tr>
						<td>
							강수 <%=weather.getTenveningRainPercent() %>%
						</td>
					</tr>										
				</table>			
			</td>
		</tr>		
	</table>

</body>
</html>



